/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package ua.yandex.skipasssystem.skipass;

import java.util.Calendar;
import java.util.Date;

/**
 *
 * @author Mitya
 */
public class SeasonSkiPass extends AbstractSkiPass {

    private static final int MONTH_IN_SEASON = 12;

    SeasonSkiPass(Date activationDate) {
        this.activationDate = activationDate;
        Date expirationDateLocal = addMonth(activationDate, MONTH_IN_SEASON);
        this.expirationDate = expirationDateLocal;
        this.type = SkiPassType.SEASON;
    }

    
    private static Date addMonth(Date date, int numberOfMonth) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.MONTH, numberOfMonth);
        return calendar.getTime();
    }


    @Override
    public boolean isValid() {
        if (isBlocked()) {
            return false;
        }

        if (isExpired()) {
            return false;
        }

        return true;
    }

    @Override
    public String toString() {
        return this.type + " " + this.activationDate.toString();
    }

    @Override
    public SkiPassType getType() {
        return this.type;
    }

}
